import React from 'react'
// ===================================================================== Temp
import FormModal from '#cpt/temp/FormModal'
// ===================================================================== global declare
const { $fn, $http, $Lazy } = window
// ===================================================================== $Lazy
const confirm 			= $Lazy.file(()=>import('@antd/confirm'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		// 提交表单列表
		formData : [
			{ label: '报告单编号',   name: 'rp_number',  full:true, 	type:'textarea', required:true,onValue:({value})=>{
				this.getSpec(value)
				this.submit.rp_number = this.getSpec(value)
			} },
			{ label: '采样时间',   name: 'coll_time',  full:true, 	type:'date-time', after:true },
			{ label: '接收时间',   name: 'check_time', full:true, 	type:'date-time', after:true },
			{ label: '报告时间',   name: 'report_at',  full:true, 	type:'date-time', after:true },
		]
	}
	submit = {}
	
	open = (rows) => {
		this.modal.open({ formRef: this.formRef })
		// 选中时默认填充报告单编号 2021-12-24  --马婷 
		if(rows){
			const spec_num = rows.map(v=>v.spec_num)
			this.formRef.setValue({rp_number: spec_num.join('\r')})
		}
	}
	// 解析条码
	getSpec(data){
		const arr = data.split(/[\s\n]/)
		const stack = []
		arr.forEach(v => {
			// if( v.length === 11 || v.length === 12 || v.length === 14 ){
			// 	stack.push(v)
			// }
			/* 报告单管理修改时间参数修改 2021-08-23  --耿琰 */
			stack.push(v)
		})
		const rp_number = Array.from(new Set(stack)).join(',')
		this.setState({ rp_number })
		return rp_number
	}
	/* 报告单管理新增修改时间按钮 2021-08-10  --耿琰 */
	render(){
		return (
			<>
				{/* 修改时间 */}
				{FormModal.call(this,{ title: '修改时间', labelWidth:'s7', width:600,enter:false,
					onSubmit:()=>{
						const datas = this.formRef.getValue()
						datas.rp_number = this.getSpec(datas.rp_number)
						confirm.then(f=>{
							this.confirm = f({
								msg:`是否确认修改时间？`,
								closable:true,
								onOk:()=> {
									$http.submit(this,'kd-report-spec/upjsondata',{ param:datas,loading:true}).then((data)=>{
										$fn.msg.success('时间修改成功')
										this.modal.close()
									})
								}
							})
						})
					},
				})}
				
			</>
		)
	}
}

export default Index